#ifndef POLYGONADDTOOL_H
#define POLYGONADDTOOL_H

#include "Common/Algebra/Vec2.h"
#include "Common/Geometry/Polygon.h"

#include "Input/EventArgs/MouseButtonEventArgs.h"
#include "Input/EventArgs/MouseMoveEventArgs.h"
#include "Input/EventArgs/MouseScrollEventArgs.h"
#include "Input/EventArgs/KeyEventArgs.h"

#include "EditorCore/Actions/IAction.h"
#include "EditorCore/Actions/ListAction.h"
#include "EditorCore/Tools/ITool.h"
#include "Entities/BodyEntity.h"

class PolygonAddTool : public editor_core::ITool
{
public:
	PolygonAddTool( BodyEntity* parentBody );
	virtual ~PolygonAddTool();

	virtual editor_core::IAction* Activate();
	virtual editor_core::IAction* Deactivate();
	virtual editor_core::IAction* ProcessMouseButtonPress( input::MouseButtonEventArgs* mouseButtonEventArgs );
	virtual editor_core::IAction* ProcessMouseButtonRelease( input::MouseButtonEventArgs* mouseButtonEventArgs );
	virtual editor_core::IAction* ProcessMouseMove( input::MouseMoveEventArgs* mouseMoveEventArgs );
	virtual editor_core::IAction* ProcessMouseScroll( input::MouseScrollEventArgs* mouseScrollEventArgs );
	virtual editor_core::IAction* ProcessKeyPress( input::KeyEventArgs* keyEventArgs );
	virtual editor_core::IAction* ProcessKeyRelease( input::KeyEventArgs* keyEventArgs );

private:
	void RefreshTempAction( const cmn::IIterable<cmn::Vec2>& vertices, BodyEntity* parentBody );
	editor_core::IAction* CreateAction( const cmn::IIterable<cmn::Vec2>& vertices, BodyEntity* parentBody );
	cmn::Vec2 CalculateCenter( const cmn::IIterable<cmn::Vec2>& vertices );

private:
	cmn::Vec2 m_center;
	cmn::Vector<cmn::Vec2> m_vertices;

	editor_core::IAction* m_tempAction;
	BodyEntity* m_parentBody;
};

#endif
